set more off
global user "`c(username)'"
*** Set WD
cd "/Users//$user/Dropbox/SurveyCovid19/"


*** Directories
global data "Descriptive paper/Clean Data/"
global tables "Descriptive paper/Tables/"
global figures "Descriptive paper/Submission Material Plos One/Replication Material/"
global enddate"01may2020"

use "$figures/data_figures1-3.dta", clear




*** Figure 1: Employment and Business loss by income

* Country + cross country weights
replace perdioempleo=perdioempleo*100
replace cerronegocio=cerronegocio*100

preserve
collapse (mean) perdioempleo cerronegocio (first) pop [w=ipw], by(idpais ingreso_antes)

reg perdioempleo ibn.ingreso_antes i.idpais [w=pop], r nocons
estimates store Employment
reg cerronegocio ibn.ingreso_antes i.idpais [w=pop], r nocons
estimates store Business

coefplot (Employment, offset(-0.05) ciopts(color(blue)) color(blue)) (Business, offset(0.05) ciopts(color(red)) color(red)), keep(*.ingreso_antes) vertical scheme(s1mono) yline(0) xtitle("Income in Jan. 2020 (in min. wages)") ytitle("Share %") ylabel(-20(20)100) recast(connected) legend(order(2 "Job loss" 4 "Business closure"))
graph export "${figures}Figure1.pdf", replace
graph export "${figures}Figure1.eps", replace

graph close
restore


* Pooled (Raw, no weights)

reg perdioempleo ibn.ingreso_antes i.idpais, r nocons
estimates store Employment
reg cerronegocio ibn.ingreso_antes i.idpais, r nocons
estimates store Business

coefplot (Employment, offset(-0.05) ciopts(color(blue)) color(blue)) (Business, offset(0.05) ciopts(color(red)) color(red)), keep(*.ingreso_antes) vertical scheme(s1mono) yline(0) xtitle("Income in Jan. 2020 (in min. wages)") ytitle("Share %") ylabel(-20(20)100) recast(connected) legend(order(2 "Job loss" 4 "Business closure"))
graph export "${figures}SFigure1.pdf", replace
graph export "${figures}SFigure1.eps", replace
graph close





*** Figure 2: Income distributions before and after the pandemic

preserve
keep if date>td(13apr2020) & date<td($enddate)
drop if ingreso_ahora==. | ingreso_antes==.
gen cou=1
collapse (sum) cou [w=ipw_c], by(ingreso_antes)
egen tot=total(cou)
gen share_antes=cou/tot
ren ingreso_antes ingreso
tempfile aux
save "`aux'", replace
restore
preserve
keep if date>td(13apr2020) & date<td($enddate)
drop if ingreso_ahora==. | ingreso_antes==.
gen cou=1
collapse (sum) cou [w=ipw_c], by(ingreso_ahora)
egen tot=total(cou)
gen share_ahora=cou/tot
ren ingreso_ahora ingreso
merge 1:1 ingreso using "`aux'", nogen

label value ingreso ingres_antes
label var ingreso "Income in minimum wages"

replace share_antes=share_antes*100
replace share_ahora=share_ahora*100

twoway (line share_antes ingreso, lcolor(blue)) (line share_ahora ingreso, lcolor(red) lpattern(dash)), yscale(range(0)) xlabel(1 "<1" 2 "1-2" 3 "2-3"  4 "3-4" 5 "4-6" 6 "6-8" 7 "8-11" 8 ">11") scheme(s1mono) ytitle("Share (%)") legend(label(1 "Income in Jan. 2020") label(2 "Income in Apr. 2020"))
graph export "${figures}Figure3.pdf", replace
graph export "${figures}Figure3.eps", replace
graph close
restore


* Pooled (raw, no weights)

preserve
keep if date>td(13apr2020) & date<td($enddate)
drop if ingreso_ahora==. | ingreso_antes==.
gen cou=1
collapse (sum) cou, by(ingreso_antes)
egen tot=total(cou)
gen share_antes=cou/tot
ren ingreso_antes ingreso
tempfile aux
save "`aux'", replace
restore
preserve
keep if date>td(13apr2020) & date<td($enddate)
drop if ingreso_ahora==. | ingreso_antes==.
gen cou=1
collapse (sum) cou, by(ingreso_ahora)
egen tot=total(cou)
gen share_ahora=cou/tot
ren ingreso_ahora ingreso
merge 1:1 ingreso using "`aux'", nogen

label value ingreso ingres_antes
label var ingreso "Income in minimum wages"

replace share_antes=share_antes*100
replace share_ahora=share_ahora*100

twoway (line share_antes ingreso, lcolor(blue)) (line share_ahora ingreso, lcolor(red) lpattern(dash)), yscale(range(0)) xlabel(1 "1" 2 "1-2" 3 "2-3"  4 "3-4" 5 "4-6" 6 "6-8" 7 "8-11" 8 "+11") scheme(s1mono) ytitle("Share (%)") legend(label(1 "Income in Jan. 2020") label(2 "Income in Apr. 2020"))
graph export "${figures}SFigure2.pdf", replace
graph export "${figures}SFigure2.eps", replace
graph close
restore






*** Figure 3: Agreement with business closures by income

* Country + cross country weights
replace h_tiempo_cerrar=h_tiempo_cerrar*100

gen loss=perdioempleo==100 | cerronegocio==100

reg h_tiempo_cerrar ibn.days_since_firstcase i.dow i.idpais [w=new_factor] if loss==0, r nocons
estimates store cerrar
reg h_tiempo_cerrar ibn.days_since_firstcase i.dow i.idpais [w=new_factor] if loss==1, r nocons
estimates store cerrar2

coefplot (cerrar, offset(-0.05) ciopts(color(blue)) color(blue)) (cerrar2, offset(0.05) ciopts(color(red)) color(red)), keep(*.days_since_firstcase) vertical scheme(s1mono) xtitle("Days since first case") xlabel(1 "30" 2 "31" 3 "32" 4 "33" 5 "34" 6 "35" 7 "36" 8 "37" 9 "38" 10 "39" 11 "40" 12 "41" 13 "42" 14 "43" 15 "44" 16 "45" 17 "46" 18 "47" 19 "48" 20 "49" 21 "50" 22 "51" ) ytitle("Share (%)") recast(connected) legend(order(2 "Did not lose job or close business" 4 "Lost job or closed business") rows(2))
graph export "${figures}Figure4.pdf", replace
graph export "${figures}Figure4.eps", replace




reg h_tiempo_cerrar ibn.days_since_firstcase i.dow i.idpais if loss==0, r nocons
estimates store cerrar
reg h_tiempo_cerrar ibn.days_since_firstcase i.dow i.idpais if loss==1, r nocons
estimates store cerrar2

coefplot (cerrar, offset(-0.05) ciopts(color(blue)) color(blue)) (cerrar2, offset(0.05) ciopts(color(red)) color(red)), keep(*.days_since_firstcase) vertical scheme(s1mono) xtitle("Days since first case") xlabel(1 "30" 2 "31" 3 "32" 4 "33" 5 "34" 6 "35" 7 "36" 8 "37" 9 "38" 10 "39" 11 "40" 12 "41" 13 "42" 14 "43" 15 "44" 16 "45" 17 "46" 18 "47" 19 "48" 20 "49" 21 "50" 22 "51" ) ytitle("Share (%)") recast(connected) legend(order(2 "Did not lose job or close business" 4 "Lost job or closed business") rows(2))
graph export "${figures}SFigure3.pdf", replace
graph export "${figures}SFigure3.eps", replace


